package com.demo.common.feign;

import com.demo.common.entity.User;
import com.demo.common.util.R;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * FeignFallBackFactory 异常信息工厂类
 *
 * @author YT
 * @date 2019-05-02
 */
@Component
@Slf4j
public class UserFeignFallBackFactory implements FallbackFactory<UserFeign> {
    @Override
    public UserFeign create(Throwable throwable) {
        return new UserFeign(){
            @Override
            public R getUser(User user) {
                user.setName("UserFeignFallBackFactoy 打印异常");
                return new R<>(user);
            }

            @Override
            public R saveUser() {
                return new R<>();
            }
        };
    }
}
